package org.flint92.springboot.mbean.simple;

import javax.management.*;
import java.lang.management.ManagementFactory;
import java.util.concurrent.CountDownLatch;

/**
 * @author flint92
 */
public class MBeanDemo {

    public static void main(String[] args) throws Exception {
        // Agent Level
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

        SimpleData simpleData = new SimpleData();

        mBeanServer.registerMBean(simpleData, create(simpleData));

        // no stop
        new CountDownLatch(1).await();
    }

    private static ObjectName create(Object mBean) throws MalformedObjectNameException {
        Class<?> clazz = mBean.getClass();

        String packageName = clazz.getPackage().getName();
        String simpleName = clazz.getSimpleName();

        return new ObjectName(packageName + ":type=" + simpleName);
    }

}
